<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
	<th:block th:include="include :: header('自定义导航快捷功能')" />
	<link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/style/dtree/dtree.css}" media="all" />
	<link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/style/dtree/font/dtreefont.css}" media="all">
	<style type="text/css">
		body {
			display: flex;
			align-items: center;
			justify-content: space-around;
			padding-top: 5px;
		}

		.dtree-box {
			height: calc(100vh - 10px);
			width: calc(50% - 40px) !important;
			overflow: auto;
			border: 1px solid rgba(0, 0, 0, .25);
			border-radius: 5px;
		}

		.dtree-box>.dtree-nav-item {
			padding-left: 0px;
		}

		.btn-box {
			display: flex;
			flex-direction: column;
		}

		.btn-box .layui-btn {
			dispaly: inline-block;
			padding: 0 10px;
		}

		.btn-box .layui-btn+.layui-btn {
			margin-left: 0;
			margin-top: 10px;
		}
	</style>
</head>

<body>
	<div class="dtree-box" id="dhtree"></div>
	<div class="btn-box">
		<div class="layui-btn dtree-btn">
			<p class="layui-icon layui-icon-release"></p>
		</div>
		<div class="layui-btn dtree-btn">
			<p class="layui-icon layui-icon-refresh"></p>
		</div>
	</div>
	<div class="dtree-box" id="dhtree2"></div>
	<th:block th:include="include :: footer" />
	<script th:src="@{/dhecp/js/left-tree.js?v=1}"></script>
	<script th:src="@{/dhecp/js/dh-business.js?v=1}"></script>
	<script type="text/javascript">
		var dtree, layer;
		layui.extend({
			dtree: '/js/layuiadmin-1.2.1/lib/extend/dtree'
		}).use(['table', 'form', 'layer', 'jquery', 'util', 'dtree'], function () {
			dtree = layui.dtree;
			var treeData = getTree('/system/menu/listtreeselectjson?menuType=ByModule');
			$.get("/system/indexmodule/list", function (res) {
				if (res.code == 0) {
					$.each(treeData, function (i, v) {
						if (v.children.length > 0) {
							$.each(v.children, function (ii, vv) {
								if (vv.children.length > 0) {
									$.each(vv.children, function (iii, vvv) {
										$.each(res.data, function (j, k) {
											if (vvv.moduleTable == k
												.moduleTable) treeData[i]
												.children[ii].children[iii]
												.checkArr = [{
													"type": "0",
													"checked": "1"
												}];
										})
									})
								}
							})
						}
					})
					CommonTreet = dtree.render({
						elem: "#dhtree",
						data: treeData,
						record: true,
						checkbar: true,
						checkbarLoad: "node",
						checkbarType: "no-all",
						checkbarData: "choose",
						done: function (res, $ul, first) {
							// 						dtree.initAllCheck("dhtree");//复选框选中状态初始化设置
							dtree.initNoAllCheck("dhtree"); //复选框半选状态初始化设置
							var treeData2 = dtree.getCheckbarNodesParam("dhtree"); //获取选中数据
							for (var i = treeData2.length - 1; i >= 0; i--) {
								if (treeData2[i].level != 3) treeData2.splice(i, 1); //删除一项
							}
							dtree.render({
								elem: "#dhtree2",
								response: {
									treeId: "nodeId",
									title: "context"
								},
								data: treeData2
							});
						}
					});
					dtree.on("node(dhtree)", function (obj) { // 绑定节点点击事件
						var nodeId = obj.param.nodeId;
						CommonTreet.clickNodeCheckbar(nodeId); // 点击节点选中复选框
					});
				} else $.modal.msgError(res.msg);
			});
			$('.layui-icon-release').click(function () { //更新
				var treeData2 = dtree.getCheckbarNodesParam("dhtree"); //获取选中数据
				if (treeData2.length == 0) {
					$.modal.msgError("请至少选择一个节点");
					dtree.reload("dhtree2", {
						data: []
					});
				} else {
					for (var i = treeData2.length - 1; i >= 0; i--) {
						if (treeData2[i].level != 3) treeData2.splice(i, 1); //删除一项
					}
					dtree.reload("dhtree2", {
						data: treeData2
					});
				}
			})
			$('.layui-icon-refresh').click(function () { //重置
				$.each(CommonTreet.data, function (i, v) {
					if (v.children.length > 0) {
						$.each(v.children, function (ii, vv) {
							if (vv.children.length > 0) {
								$.each(vv.children, function (iii, vvv) {
									treeData[i].children[ii].children[iii]
										.checkArr = [{
											"type": "0",
											"checked": "0"
										}];
								})
							}
						})
					}
				})
				dtree.reload("dhtree", {
					data: CommonTreet.data
				});
				dtree.reload("dhtree2", {
					data: []
				});
			})
		})
		var callbackdata = function () {
			var pd = [];
			$.each(dtree.getCheckbarNodesParam("dhtree"), function (i, v) {
				if (v.level == 3) pd.push({
					iid: i + 1,
					moduleName: v.context,
					moduleTable: v.recordData.moduleTable
				});
			})
			return JSON.stringify(pd);
		}
	</script>
</body>

</html>